﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Seating.utils;
using Sugar.Enties;
namespace Seating
{
    public partial class Student_Login_Form : Form
    {
        public Student_Login_Form()
        {
            InitializeComponent();
        }

        private void Login_Form_Load(object sender, EventArgs e)
        {
            textBox_password.PasswordChar = '*';
        }

        private void button_login_Click(object sender, EventArgs e)
        {
            string username = textBox_username.Text.Trim();
            string password = textBox_password.Text.Trim();

            if (!checkFrontData(username, password))
            {
                return;
            }
            Tb_StudentManager manager = new Tb_StudentManager();
            Tb_Student user = manager.GetById(username);

            if (user == null || !HashPasswordUtil.checkPassword(password, username, user.Password))
            {
                MessageBox.Show("用户名或密码错误");
                return;
            }

            LoginUserUtil.CurrentStudent = user;
            this.Hide();
            this.DialogResult = DialogResult.OK;
        }

        // 检查前段数据
        private bool checkFrontData(string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                MessageBox.Show("登录名不能为空");
                return false;
            }

            if (string.IsNullOrEmpty(password))
            {
                MessageBox.Show("密码不能为空");
                return false;
            }
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            // SqlDataReader reader = SqLHelper.ExcuteReader("select count(*) from tb_admin");
            //MessageBox.Show( reader.Read().ToString());

        }

    }
}
